var path = require('path')
var webpack = require('webpack')
var _ = require('lodash')
var ExtractTextPlugin = require("extract-text-webpack-plugin")
var BrowserSyncPlugin = require('browser-sync-webpack-plugin')

process.env.NODE_ENV = process.env.BABEL_ENV = 'development'
ENV = process.env.ENV || 'dev'
__DEV__ = (ENV === "dev")
__TEST__ = (ENV === "test")
__PROD__ = (ENV === "prod")

var provides = {
  // $: 'jquery',
  // jQuery: 'jquery',
  _: 'lodash',
  // moment: 'moment',
  React: 'react',
  ReactNative: 'react-native',
  AntdMobile: 'antd-mobile'
  // autobind: 'autobind-decorator'
}

var define = {
  __DATETIME__: JSON.stringify((new Date()).toLocaleString()),
  __DEV__: __DEV__,
  __TEST__: __TEST__,
  __PROD__: __PROD__,
  'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}

module.exports = {
  devtool: 'eval',
  entry: [
    'webpack-hot-middleware/client',
    'whatwg-fetch',
    './index.web.js'
  ],
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  resolve: {
    modulesDirectories: ['node_modules', path.join(__dirname, '../node_modules')],
    extensions: ['', '.web.js', '.js', '.jsx', '.json'],
    
  },
  plugins: [
    new webpack.DefinePlugin(define),
    new webpack.ProvidePlugin(provides),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /zh-cn/),
  ],
  module: {
    loaders: [
      { test: /\.jsx?$/, loader: 'babel?cacheDirectory=.cache', exclude: /node_modules/ },
      { test: /\.(png|jpg)$/, loader: 'file?name=./img/[name]-[hash:5].[ext]' },
      { test: /\.less$/, loader: "style!css!less"}, {
        test: /local\.less$/,
        loaders: [
          'style',
          'css?modules&importLoaders=1&localIdentName=[path]_[name]__[local]___[hash:base64:5]',
          'less'
        ],
      },
      { test: /\.css$/, loaders: ['style', 'css'] },
      { test: /\.json$/, loaders: ['json'] }
    ]
  },
  debug: true,
  noInfo: false,
  stats: {
    colors: true,
    assets: true,
    version: true,
    hash: false,
    timings: true,
    chunks: true,
    chunkModules: false
  }
}